package com.encryption.logic;

import java.util.Date;
import java.util.List;

import com.encryption.dao.Condition;
import com.encryption.dao.ManageActionLogDAO;
import com.encryption.model.ManageActionLog;
import com.encryption.rpc.model.WrapperPageInfo;

public class ManageActionLogHelper {
	private static ManageActionLogDAO actionLogDAO = ManageActionLogDAO.getInstance();
	
	public static void addLog(int actionId, String note){
		Date date = new Date();
		ManageActionLog log = new ManageActionLog(actionId, date, note);
		actionLogDAO.save(log);
	}
	
	public static WrapperPageInfo getPagingLogByCond(List<Condition> condList, int page, int pageSize){
		List<ManageActionLog> logList = actionLogDAO.findPagingByCondition(condList, page, pageSize);
		
		for (ManageActionLog log : logList){
			log.setActionName(ManageActionManager.getInstance().getByActionId(log.getActionId()).toString());
		}
		
		int recordCount = actionLogDAO.findTotalCountByCondition(condList);
		int allPageCount = (int) Math.ceil(((double)recordCount) / pageSize);
		WrapperPageInfo wraper = new WrapperPageInfo();
		wraper.setDataList(logList);
		wraper.setAllPageCount(allPageCount);
		wraper.setCurrentPage(page);
		wraper.setPageSize(pageSize);
		wraper.setRecordCount(recordCount);
		
		return wraper;
	}
}
